package com.hkjtgc.pcr_app.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.hkjtgc.pcr_app.R


const val MACHINE_TYPE_GREEN = 1
const val MACHINE_TYPE_RED = 0
data class MachineBindingVo (val machineId : String, val machineType : Int)

class BindingMachineAdapter (private val machineList : List<MachineBindingVo>) :
    RecyclerView.Adapter<BindingMachineAdapter.ViewHolder>() {


    inner class  ViewHolder(view : View) : RecyclerView.ViewHolder(view) {
        val machineImage : ImageView = view.findViewById(R.id.machine_img)
        val machineName : TextView = view.findViewById(R.id.machine_text)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : BindingMachineAdapter.ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_machine_binding,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: BindingMachineAdapter.ViewHolder, position: Int) {
        val machineInfo = machineList[position]
        //根据机器可用状态修改机器图标颜色
        if (machineInfo.machineType == MACHINE_TYPE_GREEN ) holder.machineImage.setImageResource(R.mipmap.ic_launcher)
        else holder.machineImage.setImageResource(R.mipmap.iv_machine)
        holder.machineName.text = machineInfo.machineId

    }

    override fun getItemCount(): Int  = machineList.size

}